﻿using System;
using fastCSharp;

namespace diantou.web.ajax.admin
{
    /// <summary>
    /// 比赛调用
    /// </summary>
    [fastCSharp.code.cSharp.ajax(IsPool = true)]
    class contest : permissionHandle<contest>
    {
        /// <summary>
        /// 添加比赛
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        public void Append(diantou.dataAccess.contest value, Action<fastCSharp.net.returnValue<int>> onReturn)
        {
            if ((currentUser.Permission & dataModel.user.permission.ContestEditor) != 0)
            {
                value.UserId = currentUser.Id;
                diantou.dataAccess.tcpCall.contest.append(value, onReturn);
            }
            else onReturn(0);
        }
        /// <summary>
        /// 修改比赛
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        public void Rework(diantou.dataAccess.contest value, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if ((currentUser.Permission & dataModel.user.permission.ContestEditor) != 0)
            {
                value.UserId = currentUser.Id;
                diantou.dataAccess.tcpCall.contest.rework(value, onReturn);
            }
            else onReturn(false);
        }
        /// <summary>
        /// 发布外部比赛
        /// </summary>
        /// <param name="id"></param>
        /// <param name="onReturn"></param>
        public void Submit(int id, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if ((currentUser.Permission & dataModel.user.permission.ContestEditor) != 0)
            {
                diantou.dataAccess.tcpCall.contest.submit(id, currentUser.Id, onReturn);
            }
            else onReturn(false);
        }
        ///// <summary>
        ///// 复制比赛
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="onReturn"></param>
        //public void Copy(int id, Action<fastCSharp.net.returnValue<int>> onReturn)
        //{
        //    if (currentUser.Permission == dataModel.user.permission.Admin) diantou.dataAccess.tcpCall.contest.copy(id, onReturn);
        //    else onReturn(0);
        //}
        /// <summary>
        /// 通知比赛出题人
        /// </summary>
        /// <param name="id"></param>
        /// <param name="onReturn"></param>
        public void NoticeProblemUser(int id, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.dataAccess.tcpCall.contest.noticeProblemUser(id, onReturn);
            else onReturn(false);
        }
        /// <summary>
        /// 删除问题
        /// </summary>
        /// <param name="contestId"></param>
        /// <param name="problemId"></param>
        /// <param name="onReturn"></param>
        public void DeleteProblem(int contestId, int problemId, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.dataAccess.tcpCall.contestProblem.delete(contestId, problemId, onReturn);
            else onReturn(false);
        }
        /// <summary>
        /// 添加问题
        /// </summary>
        /// <param name="contestId"></param>
        /// <param name="problemId"></param>
        /// <param name="onReturn"></param>
        public diantou.dataModel.problem AddProblem(int contestId, int problemId)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin && diantou.dataAccess.tcpCall.contestProblem.append(contestId, problemId).Value)
            {
                diantou.dataAccess.problem problem = diantou.dataAccess.clientCache.Problem[problemId].Clone();
                problem.Source = diantou.dataAccess.clientCache.User[problem.UserId].Name;
                return problem;
            }
            return null;
        }
        /// <summary>
        /// 删除所有者
        /// </summary>
        /// <param name="contestId"></param>
        /// <param name="userId"></param>
        /// <param name="onReturn"></param>
        public void DeleteOwner(int contestId, int userId, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.dataAccess.tcpCall.contestOwner.delete(contestId, userId, onReturn);
            else onReturn(false);
        }
        /// <summary>
        /// 设置竞赛问题的自动发布时间
        /// </summary>
        /// <param name="id"></param>
        /// <param name="onReturn"></param>
        public void ReworkProblemAutoShowTime(int id, Action<fastCSharp.net.returnValue<int>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.dataAccess.tcpCall.problem.reworkContestAutoShowTime(id, onReturn);
            else onReturn(0);
        }
        /// <summary>
        /// Judge数据同步
        /// </summary>
        /// <param name="id"></param>
        /// <param name="onReturn"></param>
        public void RestoreJudge(int id, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.dataAccess.tcpCall.contest.restoreJudge(id, onReturn);
            else onReturn(false);
        }
    }
}
